package utils;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.servlet.http.HttpServletResponse;

public class WritePicture {
	
	public static void writePic(HttpServletResponse response,byte[] b){
		InputStream in = new ByteArrayInputStream(b); 
		OutputStream out;
		try {
			out = response.getOutputStream();
			byte[] buf = new byte[512];
			response.setHeader("Content-Disposition", "attachment;filename=foobar.jpg");//声明下载任务 
			int len = 0;
			while((len=in.read(buf))!=-1){
				out.write(buf,0,len);
			}
			in.close();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
